package cn.xdj.blue.java.netty5.packageProm.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

public class ServerHandler extends ChannelHandlerAdapter {
	public static Logger logger = LoggerFactory.getLogger(ServerHandler.class);
	
	@Override
	//@Skip
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		logger.debug("--exceptionCaught--");
		super.exceptionCaught(ctx, cause);
	}

	@Override
	@Skip
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		logger.debug("--channelActive--");
		super.channelActive(ctx);
	}

	@Override
	@Skip
	public void channelInactive(ChannelHandlerContext ctx) throws Exception {
		logger.debug("--channelInactive--");
		super.channelInactive(ctx);
	}

	@Override
	@Skip
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		logger.debug("--channelRead--");
		String request = (String)msg;
		logger.debug("c_request:"+request);
		ByteBuf response = Unpooled.copiedBuffer("I'm Server!".getBytes());
		ctx.write(response);
	}

	@Override
	@Skip
	public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
		logger.debug("--channelReadComplete--");
		ctx.flush();
	}

}
